package com.dragon.repository.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dragon.repository.entity.Goods;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

/**
 * <p>
 * 产品 表 Mapper 接口
 * </p>
 *
 * @author sy
 * @since 2023-06-30
 */
@Mapper
public interface GoodsMapper extends BaseMapper<Goods> {

    @Select("<script>" +
            "SELECT M.* FROM" +
            "(SELECT a.*, b.customer_name AS customerName  FROM dragon_goods a INNER JOIN dragon_customer b ON a.customer_id = b.id) M  " +
            "<if test='search!=null and search != \"\"'> " +
            "WHERE (M.goods_name like CONCAT('%',#{search},'%')) " +
            "</if> "+
            "</script>")
    Page<Goods> goodsList(Page<Goods> goodsPage, String search);

    @Select("SELECT MAX(goods_num) FROM dragon_goods WHERE goods_num LIKE CONCAT(#{code},'%')")
    String maxRoundInoutNumber(String code);
}
